/**
 * @Author：ming
 * @Date：2023/10/21 12:28 PM
 * @Filename：LC128
 */

import java.util.Arrays;

/**
 * @author ming
 */
public class LC128 {
    public int longestConsecutive(int[] nums) {

        Arrays.sort(nums);
        int len = nums.length;
        if(len==0){
            return 0;
        }
        if(len==1){
            return 1;
        }
        int count = 1;
        int max = 0;
        for (int i = 1; i < len; i++) {
            if (nums[i] == nums[i - 1]) {
            } else if (nums[i] - nums[i - 1] == 1) {
                count++;
            }else {
                count = 1;
            }

            if(count>max){
                max = count;
            }

        }
        return max;
    }
}
